package network.e2e;

import java.io.IOException;

import network.link.FrameOutputStream;

/**
 * Reader for FrameInputStream
 */

public class FrameWriter {
  
  private FrameOutputStream frame_output_stream_;
  
  /**
   * Constructs a frame writer that writes to a frame output stream
   * @requires frame_output_stream not null
   * @param frame_output_stream write to which
   */
  public FrameWriter(FrameOutputStream frame_output_stream) {
    assert (frame_output_stream != null);
    frame_output_stream_ = frame_output_stream;
  }
  
  /**
   * Writes a message
   * @requires message not null
   * @param message message to be written
   * @throws IOException 
   */
  public void writeString(String message) throws IOException {
    assert (message != null);
    frame_output_stream_.write(message.getBytes());
  }
  
  /**
   * Flushes the buffers
   * @throws IOException 
   */
  public void flush() throws IOException {
    frame_output_stream_.flush();
  }
  
  /**
   * Writes a long
   * @requires number not null
   * @param number number to be written
   * @throws IOException
   */
  public void writeLong(Long number) throws IOException {
    assert number != null;
    writeString(number.toString());
  }
  
  /**
   * Writes an int
   * @requires number not null
   * @param number number to be written
   * @throws IOException
   */
  public void writeInt(Integer number) throws IOException {
    assert number != null;
    writeLong(number.longValue());
  }
  
  /**
   * Closes this writer
   */
  public void close() {
    frame_output_stream_.close();
  }
  
}
